﻿using System;
using System.IO;
using System.Threading.Tasks;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace NTmdb.TestProject
{
    /// <summary>
    ///     This is a test class for TmdbImageTest and is intended
    ///     to contain all TmdbImageTest Unit Tests
    /// </summary>
    [TestClass]
    public class TmdbImageTest
    {
        /// <summary>
        ///     A test for TmdbImage Constructor
        /// </summary>
        [TestMethod]
        public void TmdbImageConstructorTest()
        {
            var target = new TmdbImage();
            Assert.IsNotNull( target );
        }

        /// <summary>
        ///     A test for VoteAverage
        /// </summary>
        [TestMethod]
        public void VoteAverageTest()
        {
            var target = new TmdbImage();
            double expected = new Random().Next( 0, Int32.MaxValue );
            target.VoteAverage = expected;
            double actual = target.VoteAverage;
            Assert.AreEqual( expected, actual );
        }

        /// <summary>
        ///     A test for VoteCount
        /// </summary>
        [TestMethod]
        public void VoteCountTest()
        {
            var target = new TmdbImage();
            int expected = new Random().Next( 0, Int32.MaxValue );
            int actual;
            target.VoteCount = expected;
            actual = target.VoteCount;
            Assert.AreEqual( expected, actual );
        }

        /// <summary>
        ///     A test for Serialize & Deserialize
        /// </summary>
        [TestMethod]
        [DeploymentItem(@"..\..\TestData\image.json.txt")]
        public async Task SerializeDeserializeTest()
        {
            var target = new TmdbImage();
            var jsonContent = File.ReadAllText("image.json.txt");
            var actual = await target.DeserializeJson<TmdbImage>(jsonContent);

            Assert.AreEqual(1.78, actual.AspectRatio);
            Assert.AreEqual("/8uO0gUM8aNqYLs1OsTBQiXu0fEv.jpg", actual.FilePath);
            Assert.AreEqual(720, actual.Height);
            Assert.AreEqual(null, actual.Iso639_1);
            Assert.AreEqual(1280, actual.Width);
            Assert.AreEqual(5.51921973608721, actual.VoteAverage);
            Assert.AreEqual(20, actual.VoteCount);
        }
    }
}